package com.zhouyu.nettysvr.handler;

import com.zhouyu.nettysvr.proto.PeopleProto;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 业务处理
 * @author: zhouyu
 * @create: 2020-05-09 12:15
 */
@Slf4j
public class ProtobufServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        log.info("服务端收到消息,开始处理:{}",msg);
        PeopleProto.People people= (PeopleProto.People) msg;
        PeopleProto.People.Builder builder = PeopleProto.People.newBuilder();
        builder.setAge(32);
        builder.setName("zhouguilin");
        builder.setLike("serverToClient");
        ctx.writeAndFlush(builder.build());
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        log.info("channelReadComplete");
        ctx.fireChannelReadComplete();
    }
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        log.info("连接开始了....");
        ctx.fireChannelActive();
    }
}
